﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.Base;

namespace ERP_RORZE_PRODUCT.Product.MO
{
    public partial class ctrlMONGCheckDetail : DevExpress.XtraEditors.XtraUserControl
    {
        ClsMODAO clsMODAO = new ClsMODAO();
        DataTable dt;
        public ctrlMONGCheckDetail()
        {
            InitializeComponent();
        }
        void Reload(object sender, EventArgs e)
        {
            dt = clsMODAO.GetAllNGChek();
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
        }
        private void ctrlMONGCheckDetail_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            frm_MONGCheckInput frmAdd = new frm_MONGCheckInput();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.ShowDialog();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            frm_MONGCheckEdit frmEdit = new frm_MONGCheckEdit();
            frmEdit.Reload += new EventHandler(Reload);
            frmEdit.ID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString();
            frmEdit.Date = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Date").ToString();
            frmEdit.MONo = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MONo").ToString();
            frmEdit.StaffID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "StaffID").ToString();
            frmEdit.OptionID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "OptionID").ToString();
            frmEdit.justment = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Justment").ToString();
            frmEdit.Qty = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Qty").ToString();
            frmEdit.Note = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Note").ToString();
            frmEdit.Finished = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Finished").ToString();
            frmEdit.ShowDialog();
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            ClsNGCheckTable b = new ClsNGCheckTable();
            b.ID = int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString());
            clsMODAO.DeleteNGCheck(b);
            Reload(sender, e);
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            btEdit_Click(sender, e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            btDelete_Click(sender, e);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            btnAddNew_Click(sender, e);
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            clsConstantsFuction.ExportToExcel(gridView1, 1, true);
        }
    }
}
